package com.wxxymakers.grademark.config;

import com.wxxymakers.grademark.exception.ServiceException;
import com.wxxymakers.grademark.exception.TipServiceException;
import com.wxxymakers.grademark.utils.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @AUTHOR soft
 * @DATE 2018/12/21 16:20
 * @DESCRIBE
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public RestResponse sh(ServiceException e) {
        log.error(e.getMessage());
        return RestResponse.fail(e.getMessage());
    }

    @ExceptionHandler(TipServiceException.class)
    @ResponseBody
    public RestResponse tip(TipServiceException e) {
        log.warn(e.getMessage()); // 提示异常
        return RestResponse.tip(e.getMessage(), 100);
    }
}
